﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

using AjaxPro;

namespace OgilvyOne.Sharan.BLL
{
    [Serializable]
    [AjaxNamespace("ModelDocument")]
    public class ModelDocument
    {
        private string _modelXml;
        private XmlDocument _modelDoc;

        public string ModelXml
        {
            get { return _modelXml; }
            set { _modelXml = value; }
        }

        public XmlDocument Document
        {
            get { return _modelDoc; }
            set { _modelDoc = value; }
        }

        public ModelDocument(string modelXml)
        {
            _modelXml = modelXml;
            _modelDoc = new XmlDocument();
            _modelDoc.LoadXml(_modelXml);
        }

        [AjaxMethod()]
        public string GetProperty(string propertyName)
        {
            string text = string.Empty;
            XmlNode node = _modelDoc.DocumentElement.SelectSingleNode("./Properties/Property[@Name='" + propertyName + "']");
            if (node != null)
                text = node.InnerText;

            return text;
        }

        public XmlNodeList GetPropertyNodes()
        {
            XmlNodeList nodes = _modelDoc.DocumentElement.SelectNodes("./Properties/Property");
            return nodes;
        }

        public ModelDocument() { }
    }
}